import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";


export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },
  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "首页", icon: "dashboard" },
      },
    ],
  }
];

export const asyncRoutes = [
  {
    path: "/product",
    component: Layout,
    name: "Product",
    meta: { title: "商品管理", icon: "el-icon-goods" },
    children: [
      {
        path: "agricultural",
        name: "Agricultural",
        component: () => import("@/views/product/agriculturalProduct/index.vue"),
        meta: {title: "农产品管理"}
      },
      {
        path: "characteristic",
        name: "Characteristic",
        component: () => import("@/views/product/characteristicProduct/index.vue"),
        meta: {title: "特色农产品管理"}
      },
    ]
  },
  {
    path: "/information",
    name: "Information",
    component: Layout,
    meta: {title: "信息管理",icon:"el-icon-info"},
    children: [
      {
        path: "ad",
        name: "Ad",
        component: () => import("@/views/information/ad/index.vue"),
        meta:{title:"广告管理"}
      },
      {
        path: "message",
        name: "Message",
        component: () => import("@/views/information/message/index.vue"),
        meta:{title:"助农资讯"}
      },
      {
        path: "policy",
        name: "Policy",
        component: () => import("@/views/information/policy/index.vue"),
        meta:{title:"助农政策"}
      },
      {
        path: "order",
        name: "Order",
        component: () => import("@/views/information/order/index.vue"),
        meta:{title:"订单管理"}
      },
    ]
  },
  {
    path: "/auth",
    name: "Auth",
    component: Layout,
    meta: {title:"权限管理",icon:"el-icon-lock"},
    children: [
      {
        path: "user",
        name: "User",
        component: () => import("@/views/auth/user/index.vue"),
        meta:{title:"用户管理"}
      },
      {
        path: "account",
        name: "Account",
        component: () => import("@/views/auth/account/index.vue"),
        meta:{title:"账号管理"}
      },
      {
        path: "permission",
        name: "Permission",
        component: () => import("@/views/auth/permission/index.vue"),
        meta:{title:"角色管理"}
      }
    ]
  },
]

export const anyRoutes = [
  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true },
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
